package com.game.sharding.dao;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.game.sharding.dto.TeamMsg;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface TeamMsgDao extends BaseMapper<TeamMsg> {

    @DS("read2")
    @Select("select * from team_msg where id = #{id}")
    TeamMsg selectMsgById(@Param("id") Long id);

    /**
     * 插入消息
     *
     * @param record
     * @return
     */
    int insertTeamMsg(TeamMsg record);

    /**
     * 更新消息状态为已读
     *
     * @param receiver
     * @param sender
     * @return
     */
    int updateReadStatus(@Param("receiver") Long receiver,
                         @Param("sender") Long sender);

    /**
     * 未读消息数量
     *
     * @param receiver
     * @param sender
     * @return
     */
    Integer selectUnReadMsgNum(@Param("receiver") Long receiver,
                               @Param("sender") Long sender);

    /**
     * 最后一条消息
     *
     * @param receiver
     * @param sender
     * @return
     */
    TeamMsg selectLastMsg(@Param("receiver") Long receiver,
                          @Param("sender") Long sender);

    /**
     * 查询消息
     *
     * @param receiver
     * @param sender
     * @return
     */
    List<TeamMsg> selectMsgBySender(@Param("receiver") Long receiver,
                                    @Param("sender") Long sender,
                                    @Param("pageNum") Integer pageNum,
                                    @Param("pageSize") Integer pageSize);

    /**
     * 消息条数
     *
     * @param receiver
     * @param sender
     * @return
     */
    int selectMsgCount(@Param("receiver") Long receiver,
                       @Param("sender") Long sender);
}